package com.plz.afmt.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.plz.web.util.ReqResUtil;
import com.plz.web.base.vo.PagerResult;
import com.plz.web.base.dto.Resq;
import com.plz.web.base.dto.Resp;
import com.plz.web.base.dto.BaseIdDto;
import com.plz.web.base.dto.BaseIdsDto;
import javax.validation.Valid;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import com.plz.web.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.plz.afmt.service.SysParamsService;


import com.plz.afmt.dto.SysParamsDto;
import com.plz.afmt.dto.SysParamsQueryDto;
import com.plz.afmt.vo.SysParamsVo;
/**
 * <p>
 * 参数管理 管理
 * </p>
 *
 * @author jzc
 */
@Slf4j
@RestController
@Api(tags = "参数管理-管理")
@RequestMapping("/admin/sysParams")
public class SysParamsController extends BaseController {

    @Autowired
    private SysParamsService sysParamsService;
    /**
       * 查询分页数据
       */
    @ApiOperation(value = "查询分页数据")
    @PostMapping("/page")
    public Resp<PagerResult<SysParamsVo>> page( @RequestBody Resq<SysParamsQueryDto> requestBean){
        SysParamsQueryDto dto = getReqData(requestBean);
        PagerResult<SysParamsVo> result= sysParamsService.pageQuery(dto);
        return getRes(result);
    }

    @ApiOperation(value = "查询数据")
    @PostMapping("/list")
    public Resp<List<SysParamsVo>> list( @RequestBody Resq<SysParamsQueryDto> requestBean){
        SysParamsQueryDto dto = getReqData(requestBean);
        List<SysParamsVo>  result =   sysParamsService.listFor(dto);
        return getRes(result);
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询数据")
    @PostMapping(value = "/detail")
    public Resp<SysParamsVo> getById(@Valid @RequestBody Resq<BaseIdDto> requestBean){
        BaseIdDto dto = getReqData(requestBean);
        SysParamsVo result = sysParamsService.detail(dto.getId());
        return  getRes(result);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/add")
    public Resp<Boolean> add(@Valid @RequestBody Resq<SysParamsDto> requestBean){
        SysParamsDto dto = getReqData(requestBean);
        Boolean result = sysParamsService.addOrUpdate(dto)!=null;
        return getRes(result);
    }

    /**
     * 修改
    */
    @ApiOperation(value = "更新数据")
    @PostMapping(value = "/update")
    public Resp<Boolean> update(@Valid @RequestBody Resq<SysParamsDto> requestBean){
        SysParamsDto dto = getReqData(requestBean);
        Boolean result = sysParamsService.addOrUpdate(dto)!=null;
        return getRes(result);
    }
    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @PostMapping(value = "/del")
    public Resp<Boolean> delete(@Valid @RequestBody Resq<BaseIdsDto> requestBean){
        BaseIdsDto dto = getReqData(requestBean);
        Boolean result = sysParamsService.removeByIds(dto.getIds());
        return getRes(result);
    }

}
